// 引入request
import requets from "@/utils/request";
// 引入品牌对象及其相关的接口类型
import type { TrademarkModel, TrademarkListModel, TrademarkPageListModel } from "./model/trademarkModel";

//定义枚举数据（存储的是接口地址）

enum API {
  //根据关键字搜索品牌列表数据的地址
  GetTrademarkListByKeyword = "/admin/product/baseTrademark/findBaseTrademarkByKeyword",
  //根据id获取品牌对象数据的地址
  GetTrademarkById = "/admin/product/baseTrademark/get",
  //直接获取所有的品牌列表数据的地址
  GetTrademarkListAll = "/admin/product/baseTrademark/getTrademarkList",
  //根据品牌id数组获取品牌列表数据的地址
  GetTrademarkListByIds = " /admin/product/baseTrademark/inner/findBaseTrademarkByTrademarkIdList",
  //根据id删除品牌对象数据的地址
  DeleteTrademarkById = "/admin/product/baseTrademark/remove",
  //添加品牌对象的地址
  AddTrademark = "/admin/product/baseTrademark/save",
  //修改品牌对象的地址
  UpdateTrademark = "/admin/product/baseTrademark/update",
  //根据页码和条数获取品牌列表数据的地址
  GetTrademarkList = "/admin/product/baseTrademark",
}

//定义接口函数
//根据关键字获取品牌列表数据
export const reqGetTrademarkListByKeyword = (keyword: string) => requets.get<any, TrademarkListModel>(`${API.GetTrademarkListByKeyword}/${keyword}`);
//根据递获取品牌对象信息数据
export const reqGetTrademarkById = (id: number) => requets.get<any, TrademarkModel>(`${API.GetTrademarkById}/${id}`);
//直接获取所有的品牌列表数据
export const reqGetTrademarkListAll = () => requets.get<any, TrademarkListModel>(API.GetTrademarkListAll);
//根据品牌id数组获取对象数据
export const reqGetTrademarkListByIds = (ids: []) => requets.post<any, TrademarkListModel>(`${API.GetTrademarkListByIds}`, ids);
//添加品牌对象
export const reqAddTrademark = (tm: TrademarkModel) => requets.post<any, null>(`${API.AddTrademark},tm`);
//修改品牌对象
export const reqUpdateTrademark = (tm: TrademarkModel) => requets.put<any, null>(`${API.UpdateTrademark}`, tm);
//根据页码和条数获取品牌列表数据
export const reqGetTrademarkList = (page: number, limit: number) => requets.get<any, TrademarkPageListModel>(`${API.GetTrademarkList}/${page}/${limit}`);
//添加或者修改品牌的数据 （方便）
export const reqAddOrUpdateTrademark = (tm: TrademarkModel) => {
  if (tm.id) {
    return requets.put<any, null>(`${API.UpdateTrademark}`, tm);
  } else {
    return requets.post<any, null>(`${API.AddTrademark}`, tm);
  }
};
// 删除的接口函数
export const reqDeleteTrademarkById = (id: number) => requets.delete(`${API.DeleteTrademarkById}/${id}`);
